#include <iostream>
#include <cstdio>
#include <set>
using namespace std;
const int N = 1005;
set<int> used;
int a[N];

int main() {
	int n;
	while(scanf("%d", &n) != EOF) {
		used.clear();
		for(int i = 0; i < n; ++i) {
			scanf("%d", &a[i]);
		}
		for(int i = 0; i < n; ++i) {
			int tmp = 0;
			for(int j = i; j < i + 3 && j < n; ++j) {
				tmp = tmp * 10 + a[j];
				used.insert(tmp);
			}
		}
		int ans = 0;
		for(int i = 0; i <= 1005; ++i) {
			if(used.find(i) == used.end()) {
				ans = i;
				break;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}
